﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Windows.Forms;

using MineGoogleTranslator.Core;

namespace WinMineGoogleTranslator
{
	public partial class MainForm : Form
	{
		#region Static Fields
		public static string ApplicationName
		{
			get
			{
				return System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
			}
		}

		public static float ApplicationVersion
		{
			get
			{
				System.Diagnostics.FileVersionInfo fileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
				return float.Parse(fileVersionInfo.FileMajorPart.ToString() + "," + fileVersionInfo.FileMinorPart.ToString());
			}
		}
		#endregion

		#region Fields
		private bool mustClose = false;
		private List<TranslationLanguage> translationLanguages;
		#endregion

		#region Properties
		private List<TranslationLanguage> TranslationLanguages
		{
			get 
			{
				if (translationLanguages == null) 
				{
					translationLanguages = new List<TranslationLanguage>();

					translationLanguages.Add(new TranslationLanguage("English to Portuguese", Language.en, Language.pt));
					translationLanguages.Add(new TranslationLanguage("Portuguese to English", Language.pt, Language.en));
				}

				return translationLanguages;
			}
		}
		#endregion

		public MainForm()
		{
			InitializeComponent();
			FillLanguageComboBox();
		}

		private void FillLanguageComboBox()
		{
			languageComboBox.DataSource = TranslationLanguages;
		}

		private void translateButton_Click(object sender, EventArgs e)
		{
			LanguagePair pair = ((TranslationLanguage)languageComboBox.Items[languageComboBox.SelectedIndex]).LanguagePair;
			string text = originalTextBox.Text;

			translatedTextBox.Text = Translator.Translate(pair, text);
		}

		private void clearButton_Click(object sender, EventArgs e)
		{
			originalTextBox.Text = String.Empty;
			translatedTextBox.Text = String.Empty;
		}

		private void copyButton_Click(object sender, EventArgs e)
		{
			Clipboard.SetDataObject(translatedTextBox.Text, true);
		}

		#region Forms Events
		private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (!mustClose)
			{
				Hide();
				e.Cancel = true;
			}
		}

		private void MainForm_Shown(object sender, EventArgs e)
		{
			Hide();
		}
		#endregion

		#region TrayContextMenuStrip
		private void closeItem_Click(object sender, EventArgs e)
		{
			mustClose = true;
			Close();
		}

		private void translateItem_Click(object sender, EventArgs e)
		{
			Show();
		}
		#endregion

	}
}